package org.mine.database.migration;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MapiMysqlJdbcRead {
	final static String driver = "com.mysql.jdbc.Driver";
	final static String url = "jdbc:mysql://192.168.68.140:3306/mapi?zeroDateTimeBehavior=convertToNull&amp;autoReconnect=true&amp;failOverReadOnly=false&amp;autoReconnectForPools=true";
	final static String user = "xieweili_w";
	final static String pwd = "ppjyG9xfecQpm_j";
    
    static Connection con = null;
    static PreparedStatement statement = null;
    
    static{
    	 try {
			Class.forName(driver);
			con = DriverManager.getConnection(url, user, pwd);
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
    }
    
    public long getLastRecordId(String tableName, String primaryKey) throws Exception {
        String sql = "select max(" + primaryKey + ")  from " + tableName;//查询test表
        statement = con.prepareStatement(sql);
        ResultSet res = statement.executeQuery();
        if(res.next()){
        	return res.getLong(1);
        }else{
        	throw new Exception();
        }
    }
    
}